/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-19
 * Time: 23:04
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Windows.Forms;

using Labb4.Pooman.Cards;
using Labb4.Rules;

namespace Labb4.Pooman.Players
{
	/// <summary>
	/// Lets the player playing the game control a player.
	/// This player will be known as player1, and should be
	/// added manually to the control manager, since controls
	/// derived from the control class PoomanControl are not
	/// automatically added to the control manager
	/// 
	/// See the class <see cref="PoomanControl">PoomanControl</see>
	/// </summary>
	public class PoomanPlayerControl : PoomanControl
	{
		#region constructors
		
		/// <summary>
		/// Constructor, calls base, does nothing
		/// </summary>
		public PoomanPlayerControl() :
			base()
		{
		}
		
		#endregion
		
		#region overrides
		
		/// <summary>
		/// Lets the player control its player
		/// Updates the entity based on input from the user
		/// This is where users cards are highlighted, selected and played
		/// </summary>
		/// <param name="deltaTime"></param>
		public override void UpdateEntity(ref int deltaTime)
		{
			int x = m_InputManager.MouseX;
			int y = m_InputManager.MouseY;
			bool clicked = m_InputManager.MouseClick;
			bool playCards = m_InputManager.PlayCardPressed;
			bool chanceCard = m_InputManager.ChanceCardPressed;
			bool pickupCards = m_InputManager.PickupCardsPressed;
			
			m_Player.HighlightCard(ref x, ref y);
			m_Player.CheckAllSelectedCards();
			
			if(clicked)
			{
				m_Player.SelectCard(ref x, ref y);
			}
			
			if(playCards)
			{
				if(m_Player.CurrentHand.SelectedCards() > 0)
				{
					m_PressedPlay = true;
				}
				else
				{
					MessageBox.Show("You must select at least one card to play.\nFor help press F1.", "Pooman Rulebook");
				}
			}
			
			if(chanceCard)
			{
				if(Rules.PoomanRules.Instance.MainPoo.ChanceCard(m_Player))
				{
					m_PressedPlay = true;
				}
			}
			
			if(pickupCards)
			{
				if(PoomanRules.Instance.Rules is SetOfRulesPhase2)
				{
					m_PressedPlay = true;
				}
			}
		}
		
		/// <summary>
		/// Evaluates some cards. See <see cref="PoomanControl.EvaluateWonCards">abstract base method</see> in PoomanControl
		/// </summary>
		/// <param name="cards">The cards to evaluate</param>
		/// <returns>The result of the evaluation as an enum defined in Player</returns>
		public override Player.Evaluation EvaluateWonCards(CardPile cards)
		{
			return m_Player.EvaluateBasedOnValue(cards);
		}
		
		#endregion
	}
}
